package com.xliu.cs.openproject.lianliankan;

public class Coordinate {
	private int xpos;
	private int ypos;

	public Coordinate(int x, int y) {
		xpos = x;
		ypos = y;
	}
	public int getX() {return xpos;}
	public int getY() {return ypos;}

	@Override
	public boolean equals(Object o) {
		if (this == o) return true;
		if (o == null || getClass() != o.getClass()) return false;

		Coordinate that = (Coordinate) o;

		if (xpos != that.xpos) return false;
		return ypos == that.ypos;

	}
	@Override
	public int hashCode() {
		int result = xpos;
		result = 31 * result + ypos;
		return result;
	}
	public String toString() {
		return xpos + " " + ypos;
	}

	public static Coordinate toCoordinate(String xy) {
		String[] str = xy.split(" ");
		return new Coordinate(Integer.parseInt(str[0]), Integer.parseInt(str[1]));
	}
}
